package cisdi.mes.sm.rm.web;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cisdi.mes.sm.rm.service.StockWgtCheckMgr;

@Controller
public class StockManageCtl {
	@Autowired
	private StockWgtCheckMgr stockWgtCheckMgr;

	@RequestMapping("/rm/stockWgtCheck")
	@ResponseBody
	public Map<String, Object> matUnload(HttpServletRequest request) {
		// 获取浏览器端的输入
		String storageId = request.getParameter("storageId");
		String materialId = request.getParameter("materialId");
		String weightStr = request.getParameter("weight");

		// 定义输出
		Map<String, Object> map = new HashMap<String, Object>();
		try {
			// 对输入数据进行处理
			double weight = Double.parseDouble(weightStr);
			short rtn = stockWgtCheckMgr.checkStockWgt(storageId,materialId,weight,  request);
			switch (rtn) {
			case 0:
				map.put("success", true);
				map.put("message", "盘库成功");
				break;
			case 1:
				map.put("success", false);
				map.put("message", "料仓中没有可供盘库的物料");
				break;
			case 2:
				map.put("success", false);
				map.put("message", "盘库重量等于料仓现有重量，无需盘库");
				break;
			default:
				map.put("success", false);
				map.put("message", "盘库失败");
				break;
			}			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			map.put("success", false);
			map.put("message", e.getMessage());
		}
		return map;
	}

}
